home *** CD-ROM | disk | FTP | other *** search
- /*
- * NAME
- * parse.c - 17-May-97 18:44:07
- *
- * AUTHOR
- * Jon Rocatis
- *
- * DESCRIPTION
- * Contains the code that parses the batch files and
- * executes the commands.
- *
- */
-
- #include <ctype.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <exec/types.h>
- #include <devices/serial.h>
- #include <proto/all.h>
- #include <time.h>
- #include <string.h>
-
- #include "upload_protos.h"
- #include "serial_protos.h"
- #include "tools_protos.h"
- #include "parse_protos.h"
- #include "myecoff.h"
- #include "upload.h"
-
- /*
- * NAME
- * GetKeyWords
- *
- * FUNCTION
- * Reads a line from the batch file and seperates the keywords
- * into ptrs.
- *
- */
-
- BOOL GetKeyWords( FILE *fp, char *s1, char *s2, char *s3, char *s4 )
- {
- char input[255];
- char *result;
-
- *s1 = 0;
- *s2 = 0;
- *s3 = 0;
- *s4 = 0;
-
- result = fgets( input, sizeof(input), fp );
- if ( result == NULL )
- return( FALSE );
-
- sscanf( input, "%s %s %s %s\n", s1, s2, s3, s4 );
- // printf( "1: %s\n2: %s\n", s1, s2 );
- // printf( "3: %s\n4: %s\n\n", s3, s4 );
- return( TRUE );
- }
-
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- /*
- * NAME
- * ParseBatchFile
- *
- * FUNCTION
- * Parses the batchfile line by line. Executes the recognized commands
- *
- * INPUT
- * fp - ptr to already opened file
- *
- */
-
- BOOL LC_dload( char *str2, char *str3, char *str4 )
- {
- long addr, fsize;
- int okay;
-
- if ( dontSendData )
- return( TRUE );
-
- if ((strlen(str4) > 2) && (str4[0] == '0') && (str4[1] == 'x'))
- str4 += 2;
-
- okay = stch_l( str4, &addr ); // Converts hex-string to binary. If (okay == 0) -> bad number!
- if (okay == 0)
- {
- printf( "*** Illegal load address!\n");
- return( FALSE );
- }
-
- fsize = GetFileSize( str3 );
- if ( fsize > 0 )
- {
- BPTR fh;
-
- printf( "Data load! (File:'%s', addr: $%08x - $%08x)\n", str3, addr, addr + fsize );
- fh = Open( str3, MODE_OLDFILE );
- if (fh)
- {
- DataSend( fh, addr, fsize ); // Send the whole file
- WaitForPSX();
- Close(fh);
- }
- }
- else
- {
- printf( "*** Couldn't open '%s'!\n\n", str3 );
- return( FALSE );
- }
- return( TRUE );
- }
-
- BOOL LC_load( char *str2, char *str3, char *str4 )
- {
- UploadExe( str3 );
- return( TRUE );
- }
-
- BOOL LC_echo( char *str2, char *str3, char *str4 )
- {
- printf( "%s\n", str3 );
- return( TRUE );
- }
-
- BOOL LC_sleep( char *str2, char *str3, char *str4 )
- {
- int secs;
-
- secs = atol( str3 );
- Delay( secs * 50 );
- return( TRUE );
- }
-
- BOOL LC_beep( char *str2, char *str3, char *str4 )
- {
- DisplayBeep(NULL);
- return( TRUE );
- }
-
- BOOL LC_quit( char *str2, char *str3, char *str4 )
- {
- return( FALSE );
- }
-
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- // Table of local commands that we recognize
-
- static struct CmdTable locCmd[] =
- {
- { "dload", LC_dload },
- { "load", LC_load },
- { "echo", LC_echo },
- { "sleep", LC_sleep },
- { "beep", LC_beep },
- { "quit", LC_quit }
- };
-
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- void ParseBatchFile( FILE *fp )
- {
- BOOL stat;
- char str1[50], str2[50], str3[50], str4[50];
-
- do
- {
- stat = GetKeyWords( fp, str1, str2, str3, str4 );
- if ( stat )
- {
- if ((str1[0] == ';') || (str1[0] == '#'))
- continue;
-
- if (stricmp( "local", str1 ) == 0)
- {
- // Command is a local command
-
- LONG idx;
-
- for ( idx = 0; idx < ArrayElements( locCmd ); idx++ )
- {
- if (stricmp( locCmd[idx].cmdName, str2 ) == 0)
- {
- if (!(*(locCmd[idx].func))( str2, str3, str4 )) // Execute command
- stat = FALSE;
- break;
- }
- }
- }
- else
- {
- // Command is a SIOCONS command
-
- if (stricmp( "go", str1 ) == 0)
- SendGo();
- }
- }
- } while (stat);
- }
-
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-